home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / ole2book.zip / CHAP10.ZIP / CHAP10 / SCHMOO / IDROPSRC.CPP < prev    next >
C/C++ Source or Header  |  1993-06-13  |  4KB  |  167 lines

  1. /*
  2.  * IDROPSRC.CPP
  3.  *
  4.  * Implementation of a IDropSource implementation.
  5.  *
  6.  * Copyright (c)1993 Microsoft Corporation, All Rights Reserved
  7.  *
  8.  * Kraig Brockschmidt, Software Design Engineer
  9.  * Microsoft Systems Developer Relations
  10.  *
  11.  * Internet  :  kraigb@microsoft.com
  12.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  13.  */
  14.  
  15.  
  16. #include "schmoo.h"
  17.  
  18.  
  19.  
  20. /*
  21.  * CDropSource::CDropSource
  22.  * CDropSource::~CDropSource
  23.  *
  24.  * Constructor Parameters:
  25.  *  pDoc            LPSchmooDoc containing this interface.
  26.  */
  27.  
  28. CDropSource::CDropSource(LPCSchmooDoc pDoc)
  29.     {
  30.     m_cRef=0;
  31.     m_pDoc=pDoc;
  32.     return;
  33.     }
  34.  
  35. CDropSource::~CDropSource(void)
  36.     {
  37.     return;
  38.     }
  39.  
  40.  
  41.  
  42.  
  43. /*
  44.  * CDropSource::QueryInterface
  45.  * CDropSource::AddRef
  46.  * CDropSource::Release
  47.  *
  48.  * Purpose:
  49.  *  IUnknown members for CDropSource object.
  50.  */
  51.  
  52. STDMETHODIMP CDropSource::QueryInterface(REFIID riid, LPVOID FAR *ppv)
  53.     {
  54.     *ppv=NULL;
  55.  
  56.     //Any interface on this object is the object pointer.
  57.     if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IDropSource))
  58.         *ppv=(LPVOID)this;
  59.  
  60.     /*
  61.      * If we actually assign an interface to ppv we need to AddRef it
  62.      * since we're returning a new pointer.
  63.      */
  64.     if (NULL!=*ppv)
  65.         {
  66.         ((LPUNKNOWN)*ppv)->AddRef();
  67.         return NOERROR;
  68.         }
  69.  
  70.     return ResultFromScode(E_NOINTERFACE);
  71.     }
  72.  
  73.  
  74. STDMETHODIMP_(ULONG) CDropSource::AddRef(void)
  75.     {
  76.     return ++m_cRef;
  77.     }
  78.  
  79. STDMETHODIMP_(ULONG) CDropSource::Release(void)
  80.     {
  81.     ULONG           cRefT;
  82.  
  83.     cRefT=--m_cRef;
  84.  
  85.     if (0L==m_cRef)
  86.         delete this;
  87.  
  88.     return cRefT;
  89.     }
  90.  
  91.  
  92.  
  93.  
  94.  
  95. /*
  96.  * CDropSource::QueryDragContinue
  97.  *
  98.  * Purpose:
  99.  *  Determines whether to continue a drag operation or cancel it.
  100.  *
  101.  * Parameters:
  102.  *  fEsc            BOOL indicating that the ESC key was pressed.
  103.  *  grfKeyState     DWORD providing states of keys and mouse buttons.
  104.  *
  105.  * Return Value:
  106.  *  SCODE           DRAGDROP_S_CANCEL to stop the drag, DRAGDROP_S_DROP
  107.  *                  to drop the data where it is, or NOERROR to continue.
  108.  */
  109.  
  110. STDMETHODIMP CDropSource::QueryContinueDrag(BOOL fEsc, DWORD grfKeyState)
  111.     {
  112.     /*
  113.      *  1.  If fEsc is TRUE, you'll generally cancel the operation,
  114.      *      so return DRAGDROP_S_CANCEL.  Any other similar condition
  115.      *      should return the same value.
  116.      *
  117.      *  2.  Test the opposite condition of what you started dragging on,
  118.      *      usually a left mouse button click.  On this, cause a drop
  119.      *      by returning DRAGDROP_S_DROP.
  120.      *
  121.      *  3.  Otherwise continue dragging by returning NOERROR.
  122.      */
  123.  
  124.     if (fEsc)
  125.         return ResultFromScode(DRAGDROP_S_CANCEL);
  126.  
  127.     if (!(grfKeyState & MK_LBUTTON))
  128.         return ResultFromScode(DRAGDROP_S_DROP);
  129.  
  130.     return NOERROR;
  131.     }
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138. /*
  139.  * CDropSource::GiveFeedback
  140.  *
  141.  * Purpose:
  142.  *  Provides cursor feedback to the user since the source task
  143.  *  always has the mouse capture.  We can also provide any other
  144.  *  type of feedback above cursors if we so desire.
  145.  *
  146.  * Parameters:
  147.  *  dwEffect        DWORD effect flags returned from the last target.
  148.  *
  149.  * Return Value:
  150.  *  SCODE           NOERROR if you set a cursor yourself or
  151.  *                  DRAGDROP_S_USEDEFAULTCURSORS to let OLE do the work.
  152.  */
  153.  
  154. STDMETHODIMP CDropSource::GiveFeedback(DWORD dwEffect)
  155.     {
  156.     /*
  157.      * Implementation:
  158.      *  1.  If you want to control the cursor, case out each effect flag
  159.      *      of interest in dwEffect and SetCursor to the desired cursor,
  160.      *      then return NOERROR.
  161.      *  2.  If you do not specifically SetCursor, return
  162.      *      DRAGDROP_S_USEDEFAULTCURSORS.
  163.      */
  164.  
  165.     return ResultFromScode(DRAGDROP_S_USEDEFAULTCURSORS);
  166.     }
  167.